import { BrowserRouter as Router, useRoutes, } from 'react-router-dom'
import Login from '../pages/Login'
import Home from '../pages/Home'
import store from '../store/rabbit'
import { useLocation, Navigate } from 'react-router-dom'
import HomeLayout from '../layouts/HomeLayout'
import Category from '../pages/Category/index'
import Cart from '../pages/Cart';
import Member from '../pages/Member/index'
import Product from '../pages/Product/index';
import Order from '../pages/Order/index'
import Commodity from '../commodity/index';
 

/**
 * 路由列表
 * **/
const RouterList = () => {
 
    return useRoutes([
        {
            path: '/login',
            element: <Login></Login>
        },
        {
            path: '/',
            element: <Home></Home>,
        },
        {
            path:'homelayout',
            element:<HomeLayout/>
        },
        {
            path: '/member',
            element: <Member></Member>,
        },

        {
            path: '/member/order',
            element: <Order></Order>,
        },

        {
            path:'/category/sub',
            element:<Product/>
        },
        {
            path:'/cart',
            element:<Cart/>
        },

        {
            path:'/category',
            element:<Category/>
        },
        // 详情页
        {
            path:"/commodity/:id",
            element:<Commodity/>
        }

    ])
}

/**
 * 路由守卫
 * **/
// const Auth = ({ children }) => {
//     const { pathname } = useLocation()
//     if (pathname.startsWith('/login') && store.token) {
//         return <Navigate to="/"></Navigate>
//     }
//     if (!pathname.startsWith('/login') && !store.token) {
//         return <Navigate to="/login"></Navigate>
//     }
//     return children
// }

/**
 * 路由
 * **/
export default () => {
    return (
        <Router>
            {/* <Auth> */}
                <RouterList></RouterList>
            {/* </Auth> */}
        </Router>
    )
}